package com.spark.lola.controller.logistics;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.spark.lola.logistics.constant.LogisticsConstant;
import com.spark.lola.logistics.entity.LocationInfo;
import com.spark.lola.logistics.service.LocationInfoService;
import com.spark.lola.support.common.constant.CommonConstant;
import com.spark.lola.support.common.util.ResponseBean;
import com.spark.lola.support.mybatis.common.QueryCondition;
import com.spark.lola.support.mybatis.entity.QueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * @author: Zhi-peng wang
 * @date: 2020/05/25 13:43
 **/
@RestController
@RequestMapping(value = "/api/logistics/location", produces = "application/json;charset=utf-8")
@Api(value = "/api/logistics/location", tags = "地址")
public class LocationController {

    @Autowired
    private LocationInfoService locationInfoService;

    @ApiOperation(value = "地址")
    @RequestMapping(value = "/findBy", method = RequestMethod.POST)
    public ResponseBean findPage(@RequestBody QueryParam<LocationInfo> queryParam) {
//        queryParam.getQueryList().add(new QueryCondition("o.location_type", LogisticsConstant.LocationType.OTHER, "=", "and"));
        if (CollectionUtils.isEmpty(queryParam.getQueryList())) {
            queryParam.setQueryList(new ArrayList<>());
        }
        queryParam.getQueryList().add(new QueryCondition("o.used", CommonConstant.Y, "=", "and"));
        queryParam.setSortFields("o.updateTime_d");
        IPage<LocationInfo> locationInfoIPage = locationInfoService.findPage(queryParam);
        return ResponseBean.success(locationInfoIPage);
    }

}
